/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import model.Item;

/**
 *
 * @author Student
 */
public class InsertItem implements Action{

    @Override
    public String execute(HttpServletRequest request) {
        int id = Integer.valueOf(request.getParameter("id"));
        String nama = request.getParameter("nama");
        String keterangna = request.getParameter("keterangan");
        double harga = Double.valueOf(request.getParameter("harga"));
        
        Item item = new Item(id, nama, keterangna, harga);        
        HttpSession sesi = request.getSession(true);
        List<Item> list = (ArrayList<Item>)sesi.getAttribute("list");
        list.add(item);        
        sesi.setAttribute("list", list);
        
        return "controller?action=list_item";
        
    }
    
}
